﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Collections;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ctsu.Data;
using ctsu.Admin.Forms;
using ctsu.BaseForms;

namespace ctsu.Admin.Forms
{
	public partial class FormLookupDlg : Form
	{
		public FormLookupDlg()
		{
			InitializeComponent();
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			if (cboTables.SelectedIndex > -1)
			{
				NameVal nv = (NameVal)cboTables.SelectedItem;

				FormMain fm = (FormMain)this.Owner;
				FormInfoBase fi = fm.GetFormInfo(50, false);
				fi.TableName = nv.StringValue;
				fi.SpecialLookups = new Hashtable();
				fi.GridMeta = new Hashtable();
				fm.DisplayForm(fi);
				this.Close();
			}
			else
				MessageBox.Show(this.Parent, "Please select a table from the dropdown list");
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			this.Close();
		}

		private void FormLookupDlg_Load(object sender, EventArgs e)
		{
			LoadLookups();
		}

		private void LoadLookups()
		{
			IDataReader rdr = null;
			try
			{
				rdr = Data.DataAccess.GetDataReader("Select * FROM LookupLists_S");
				int pos =0;
				NameVal nv;

				while (rdr.Read())
				{
					nv = new NameVal();
					pos = rdr.GetOrdinal("Name");
					nv.Name = rdr.GetString(pos);
					pos = rdr.GetOrdinal("TableName");
					nv.StringValue = rdr.GetString(pos);

					cboTables.Items.Add(nv);
	
				}
				cboTables.DisplayMember = "Name";
				cboTables.ValueMember = "StringValue";
			}
			catch(Exception ex)
			{}
			finally
			{
				rdr.Close();
			}
		}

		

		private void cboTables_SelectedValueChanged(object sender, EventArgs e)
		{
			

			
			
		}
	}

}
